# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Sui Libin <bygreencn@gmail.com>

_realname=libxlsxwriter
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.5
pkgrel=1
pkgdesc="A C library for creating Excel XLSX files (mingw-w64)"
arch=('any')
url="https://github.com/jmcnamara/libxlsxwriter"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" 
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-zlib")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         #"${MINGW_PACKAGE_PREFIX}-minizip"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/jmcnamara/libxlsxwriter/archive/RELEASE_${pkgver}.tar.gz")
sha256sums=('a42daf9a96a5ba24d46a56bd0ad0d44bc4bc35f73b8aed22c4fa5f8f3e8eb8be')

prepare() {
  cd "${srcdir}/${_realname}-RELEASE_${pkgver}"
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe -Wno-dev \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_TESTS=ON \
    -DBUILD_EXAMPLES=OFF \
    -DUSE_SYSTEM_MINIZIP=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    ../${_realname}-RELEASE_${pkgver}
  make
}

check(){
  cd ${srcdir}/build-${MINGW_CHOST}
  make test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
